<template>
  <div class="tool-head">
    <div class="tool-head-content">
      <div class="tool-icon-wrapper">
        <CustomImage
          :src="tool.localLogoPath || tool.logoUrl"
          :alt="tool.toolName"
          img-class="tool-icon"
          type="logo"
        />
      </div>
      <div class="tool-info-wrapper">
        <h1 class="tool-name">{{ tool.toolName }}</h1>
        <p class="tool-description">{{ tool.description }}</p>
        <div v-if="tool.tags.length > 0" class="tool-tags">
          <span
            v-for="(tagItem, index) in processedTags"
            :key="`${tagItem.tag}-${index}`"
            class="tag-item"
            :class="[tagItem.color.bgColor, tagItem.color.textColor]"
          >
            {{ tagItem.tag }}
          </span>
        </div>
        <div class="tool-stats">
          <span class="stat-item">
            <span class="stat-icon">❤️</span>
            <span class="stat-value">{{ tool.likes || 432 }}</span>
            <span class="stat-label">点赞</span>
          </span>
          <span class="stat-item">
            <span class="stat-icon">👁️</span>
            <span class="stat-value">{{ tool.viewHotScore }}</span>
            <span class="stat-label">访问</span>
          </span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
/**
 * 工具头部组件
 * 用于展示工具的基本信息，包括图标、名称、描述、标签和统计信息
 * 适用于工具详情页等场景
 */

import type { ToolItem } from '~/types/tools'
import { processToolTags, type TagColorCombination } from '~/components/ToolCard/toolUtils'

/**
 * 组件属性定义
 */
interface Props {
  /** 工具数据 */
  tool: ToolItem
}

// 定义组件属性
const props = defineProps<Props>()

/**
 * 处理工具标签显示
 * 为每个标签分配随机颜色
 * @param {string[]} tags - 工具标签数组
 * @returns {Array<{tag: string, color: TagColorCombination}>} 处理后的标签数组
 */
const processedTags = computed<Array<{tag: string, color: TagColorCombination}>>(() => {
  return processToolTags(props.tool.tags || [])
})
</script>

<style lang="less" scoped>
.tool-head {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  padding: 32px;
  margin-bottom: 32px;
  transition: all 0.3s ease;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.tool-head:hover {
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15);
  transform: translateY(-2px);
}

.tool-head-content {
  display: flex;
  align-items: center;
  gap: 32px;
  max-width: 1400px;
  margin: 0 auto;
}

.tool-icon-wrapper {
  flex-shrink: 0;
  width: 80px;
  height: 80px;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease;
}

.tool-icon-wrapper:hover {
  transform: scale(1.05);
}

.tool-icon {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tool-info-wrapper {
  flex: 1;
  min-width: 0;
}

.tool-name {
  font-size: 36px;
  font-weight: 700;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}

.tool-description {
  font-size: 18px;
  color: #666;
  margin-bottom: 16px;
  line-height: 1.5;
  font-weight: 400;
}

.tool-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.tag-item {
  padding: 4px 12px;
  font-size: 12px;
  border-radius: 16px;
  transition: all 0.2s ease;
}

.tag-item:hover {
  transform: scale(1.05);
}

.tool-stats {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: #666;
}

.stat-icon {
  font-size: 16px;
}

.stat-value {
  font-weight: 600;
  color: #333;
}

.stat-label {
  color: #888;
}

/* 暗黑模式下的样式 */
html.dark .tool-head {
  background: var(--bg-header);
  border: 1px solid var(--border-color);
}

html.dark .tool-name {
  background: var(--btn-primary-bg);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

html.dark .tool-description {
  color: var(--text-secondary);
}

html.dark .stat-item {
  color: var(--text-secondary);
}

html.dark .stat-value {
  color: var(--text-color);
}

html.dark .stat-label {
  color: var(--text-light);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .tool-head {
    padding: 24px;
  }
  
  .tool-head-content {
    flex-direction: column;
    text-align: center;
    gap: 24px;
  }
  
  .tool-icon-wrapper {
    width: 64px;
    height: 64px;
  }
  
  .tool-name {
    font-size: 28px;
  }
  
  .tool-description {
    font-size: 16px;
  }
  
  .tool-stats {
    justify-content: center;
  }
}

@media (max-width: 480px) {
  .tool-head {
    padding: 20px;
  }
  
  .tool-name {
    font-size: 24px;
  }
  
  .tool-stats {
    flex-direction: column;
    gap: 12px;
  }
  
  .stat-item {
    justify-content: center;
  }
}
</style>